//
//  HomeSupVC.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/27.
//

#import "HomeSupVC.h"
#import <CoreLocation/CoreLocation.h>
#import "LocationUpdata.h"
#import "DataFrameParam.h"
#import "DataFrameMove.h"
#import <YYModel/YYModel.h>
@interface HomeSupVC ()<CLLocationManagerDelegate>
@property (strong, nonatomic)CLLocationManager *mag;
@end

@implementation HomeSupVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark -For Home-
- (void)MoveLocal {
    if(!self.mag){
        self.mag = [[CLLocationManager alloc] init];
        [self.mag requestWhenInUseAuthorization];
        self.mag.desiredAccuracy = kCLLocationAccuracyBest;
        self.mag.delegate = self;
    }
    [self.mag startUpdatingLocation];
}


- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray<CLLocation *> *)locations {
    
    [self.mag stopUpdatingLocation];
    
    CLLocation *currentLocal = [locations lastObject];
    [LocationUpdata sharedInstance].lat = [NSString stringWithFormat:@"%f",currentLocal.coordinate.latitude];
    [LocationUpdata sharedInstance].lot = [NSString stringWithFormat:@"%f",currentLocal.coordinate.longitude];
    
    CLGeocoder *der = [[CLGeocoder alloc] init];
    CLLocation *loc = [[CLLocation alloc] initWithLatitude:currentLocal.coordinate.latitude longitude:currentLocal.coordinate.longitude];
    [der reverseGeocodeLocation:loc completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        CLPlacemark *plk = [placemarks firstObject];
        
        NSString *likingpalate = [self fixString:plk.administrativeArea];
        NSString *bracelet = [self fixString:plk.ISOcountryCode];;
        NSString *laughedoh = [self fixString:plk.country];;
        NSString *reform = [self fixString:plk.thoroughfare];;
        NSString *house = [LocationUpdata sharedInstance].lat;
        NSString *waved = [LocationUpdata sharedInstance].lot;
        NSString *available = [self fixString:plk.locality];;
        NSString *delighted = [self fixString:plk.subLocality];;
        NSLog(@"%@",@{@"likingpalate":likingpalate,@"bracelet":bracelet,@"laughedoh":laughedoh,@"reform":reform,@"house":house,@"waved":waved,@"available":available,@"delighted":delighted});

        [DataFrameMove frameMoverForPost:@"/cham/chieftain" MoverPost:YES frameParm:@{@"likingpalate":likingpalate,@"bracelet":bracelet,@"laughedoh":laughedoh,@"reform":reform,@"house":house,@"waved":waved,@"available":available,@"delighted":delighted} finish:^(id  _Nonnull info) {
            
        }];

    }];
    
}

- (void)MoveSpokes {

    NSString *even =[DataFrameParam even];
    NSString *armyoure = [DataFrameParam armyoure];
    NSLog(@"%@",@{@"ringing":armyoure,@"overbearing":even});
    [DataFrameMove frameMoverForPost:@"/cham/spokes" MoverPost:YES frameParm:@{@"ringing":armyoure,@"overbearing":even} finish:^(id  _Nonnull info) {
        
    }];

}

- (void)MoveDice {
    NSDictionary *dice = [[LocationUpdata sharedInstance] upDataDevice];
    NSLog(@"MoveDice %@",dice);
    //fashion
    [DataFrameMove frameMoverForPost:@"/cham/herin" MoverPost:YES frameParm:@{@"fashion":[dice yy_modelToJSONString]} finish:^(id  _Nonnull info) {
        
    }];
}


- (NSString *)fixString:(id)obj {
    if([obj isEqual:[NSNull null]]){
        return @"";
    }
    if(obj == nil){
        return @"";
    }
    
    return [NSString stringWithFormat:@"%@",obj];
}
@end
